# *-* coding: utf-8 *-*
from __future__ import absolute_import

from PyQt4.QtGui import QMenu
from PyQt4.QtGui import QIcon
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QObject

from ninja_ide import resources
from ninja_ide.core import settings
from ninja_ide.gui import actions


class MenuProject(QObject):

    def __init__(self, menuProject, toolbar):
        QObject.__init__(self)

        runAction = menuProject.addAction(QIcon(resources.IMAGES['play']),
            self.tr("Run Project (F6)"))
        runFileAction = menuProject.addAction(
            QIcon(resources.IMAGES['file-run']),
            self.tr("Run File ($1+F6)", settings.OS_KEY))
        stopAction = menuProject.addAction(QIcon(resources.IMAGES['stop']),
            self.tr("Stop ($1+F5)", settings.OS_KEY))
        menuProject.addSeparator()
        previewAction = menuProject.addAction(
            self.tr("Preview Web in Default Browser"))

        toolbar.addAction(runAction)
        toolbar.addAction(runFileAction)
        toolbar.addAction(stopAction)
        toolbar.addSeparator()

        self.connect(runAction, SIGNAL("triggered()"),
            actions.Actions()._execute_project)
        self.connect(runFileAction, SIGNAL("triggered()"),
            actions.Actions()._execute_file)
        self.connect(stopAction, SIGNAL("triggered()"),
            actions.Actions()._kill_execution)
        self.connect(previewAction, SIGNAL("triggered()"),
            actions.Actions().preview_in_browser)
